package com.tac.service.wms.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.wms.MaterialApplicationDao;
import com.tac.dao.wms.MaterialApplicationMaterialDao;
import com.tac.pojo.wms.MaterialApplication;
import com.tac.pojo.wms.MaterialApplicationMaterial;
import com.tac.service.wms.MaterialApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MaterialApplicationServiceImpl implements MaterialApplicationService {

    @Autowired
    private MaterialApplicationDao materialApplicationDao;

    @Autowired
    private MaterialApplicationMaterialDao materialApplicationMaterialDao;

    //领料申请查询
    public Result<PageInfo<MaterialApplication>> getList(Integer pageNum, Integer pageSize, String receiveNumber, Date receiveTimeStart, Date receiveTimeEnd, String applicant,
                          Date applicantTimeStart, Date applicantTimeEnd, String applicantStatus, String reviewed,
                          Date reviewedTimeStart, Date reviewedTimeEnd, String reviewedStatus){
        PageHelper.startPage(pageNum,pageSize);
        List<MaterialApplication> list = materialApplicationDao.getList(receiveNumber, receiveTimeStart, receiveTimeEnd, applicant, applicantTimeStart, applicantTimeEnd, applicantStatus, reviewed, reviewedTimeStart, reviewedTimeEnd, reviewedStatus);
        PageInfo<MaterialApplication> materialApplicationPageInfo = new PageInfo<>(list);
        return Result.success(materialApplicationPageInfo);
    }

    //领料申请添加

    public Result save(MaterialApplication materialApplication){
        Integer integer = materialApplicationDao.save(materialApplication);
        if(integer<=0){
            return Result.error("领料申请添加失败");
        }else {
            return Result.success(null);
        }
    }
    //领料申请删除
    public Result remove(List<Integer> ids){
        Integer integer = materialApplicationDao.remove(ids);
        if(integer<=0){
            return Result.error("领料申请删除失败");
        }else {
            return Result.success(null);
        }
    }
    //领料申请更新
    public Result update(MaterialApplication materialApplication){
        Integer integer = materialApplicationDao.update(materialApplication);
        if(integer<=0){
            return Result.error("领料申请更新失败");
        }else {
            return Result.success(null);
        }
    }


    //生产计划明细添加
    public Result save2(MaterialApplicationMaterial materialApplicationMaterial){
        Integer integer = materialApplicationMaterialDao.save(materialApplicationMaterial);
        if(integer<=0){
            return Result.error("生产计划明细添加失败");
        }else {
            return Result.success(null);
        }
    }
    //生产计划明细删除
    public Result remove2(List<Integer> ids){
        Integer integer = materialApplicationMaterialDao.remove(ids);
        if(integer<=0){
            return Result.error("生产计划明细删除失败");
        }else {
            return Result.success(null);
        }
    }
    //生产计划明细更新
    public Result update2(MaterialApplicationMaterial materialApplicationMaterial){
        Integer integer = materialApplicationMaterialDao.update(materialApplicationMaterial);
        if(integer<=0){
            return Result.error("生产计划明细更新失败");
        }else {
            return Result.success(null);
        }
    }
}
